package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppSiteTopicUser;
import com.ruoyi.background.service.IAppSiteTopicUserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户站点答题主记录Controller
 *
 * @author susu
 * @date 2024-08-27
 */
@RestController
@RequestMapping("/applet/userTopicRecord")
public class AppSiteTopicUserController extends BaseController {
    @Autowired
    private IAppSiteTopicUserService appSiteTopicUserService;

    /**
     * 查询用户站点答题主记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppSiteTopicUser appSiteTopicUser) {
        startPage();
        List<AppSiteTopicUser> list = appSiteTopicUserService.selectAppSiteTopicUserList(appSiteTopicUser);
        return getDataTable(list);
    }

    /**
     * 导出用户站点答题主记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:export')")
    @Log(title = "用户站点答题主记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppSiteTopicUser appSiteTopicUser) {
        List<AppSiteTopicUser> list = appSiteTopicUserService.selectAppSiteTopicUserList(appSiteTopicUser);
        ExcelUtil<AppSiteTopicUser> util = new ExcelUtil<AppSiteTopicUser>(AppSiteTopicUser.class);
        util.exportExcel(response, list, "用户站点答题主记录数据");
    }

    /**
     * 获取用户站点答题主记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appSiteTopicUserService.selectAppSiteTopicUserById(id));
    }

    /**
     * 新增用户站点答题主记录
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:add')")
    @Log(title = "用户站点答题主记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppSiteTopicUser appSiteTopicUser) {
        return toAjax(appSiteTopicUserService.insertAppSiteTopicUser(appSiteTopicUser));
    }

    /**
     * 修改用户站点答题主记录
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:edit')")
    @Log(title = "用户站点答题主记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppSiteTopicUser appSiteTopicUser) {
        return toAjax(appSiteTopicUserService.updateAppSiteTopicUser(appSiteTopicUser));
    }

    /**
     * 删除用户站点答题主记录
     */
    @PreAuthorize("@ss.hasPermi('applet:userTopicRecord:remove')")
    @Log(title = "用户站点答题主记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appSiteTopicUserService.deleteAppSiteTopicUserByIds(ids));
    }
}
